package com.buba.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.buba.service.PaymentRecordService;
import common.R;
import entity.salary.PaymentRecord;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import utils.PageResult;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author beisheng
 * @since 2023-03-21
 */
@RestController
@RequestMapping("/payment-record")
public class PaymentRecordController {

    @Resource
    private PaymentRecordService paymentRecordService;

    /* *
     * @Author: beisheng
     * @Descriprion: 根据人员ID查询当年所有缴纳记录
     * @Date: 2023/3/21 19:27
     * @Return: common.R
     * @Param: [map]
     */

    @PostMapping("/selPaymentRecord")
    public R selPaymentRecord(@RequestBody Map<String,Object> map){
        List<PaymentRecord> paymentRecords = paymentRecordService.selPaymentRecord(map);
        return R.success(paymentRecords);
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 台账存档
     * @Date: 2023/3/31 13:42
     * @Return: common.R
     * @Param: [paymentRecord]
     */

    @PostMapping("/insertPaymentRecord")
    public R insertPaymentRecord(@RequestBody List<PaymentRecord> paymentRecord){
        return R.success(paymentRecordService.saveBatch(paymentRecord));
    }
    /**
     * 功能描述: 新增或更新
     *
     * @param paymentRecord
     * @return
     * @throws
     * @Author: beisheng
     */
    @PostMapping("/save")
    public R save(@RequestBody PaymentRecord paymentRecord) {
        paymentRecordService.saveOrUpdate(paymentRecord);
        return R.success();
    }

    /**
     * 功能描述: 删除
     *
     * @param id
     * @return
     * @throws
     * @Author: beisheng
     */
    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable Integer id) {
        paymentRecordService.removeById(id);
        return R.success();
    }

    /**
     * 功能描述: 批量删除
     *
     * @param ids
     * @return
     * @throws
     * @Author: beisheng
     */
    @PostMapping("/deleteBatch")
    public R deleteBatch(@RequestBody List<Integer> ids) {
        paymentRecordService.removeByIds(ids);
        return R.success();
    }

    /**
     * 功能描述: 全查
     *
     * @param
     * @return
     * @throws
     * @Author: beisheng
     */
    @GetMapping("/findAll")
    public R findAll() {
        return R.success(paymentRecordService.list());
    }

    /**
     * 功能描述: 单查
     *
     * @param id
     * @return
     * @throws
     * @Author: beisheng
     */
    @GetMapping("/findOne/{id}")
    public R findOne(@PathVariable Integer id) {
        return R.success(paymentRecordService.getById(id));
    }

    /**
     * 功能描述: 分页查询
     *
     * @param pageNum
     * @param pageSize
     * @return
     * @throws
     * @Author: beisheng
     * @Date:   2022/7/28 19:15
     */
    @GetMapping("/findPage")
    public R findPage(@RequestParam Integer pageNum,
                                 @RequestParam Integer pageSize) {
        QueryWrapper<PaymentRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        return R.success(paymentRecordService.page(new Page<>(pageNum, pageSize), queryWrapper));
    }

}
